{*
  Object Pascal simple Windows clipboard manipulation routines
  @Author  Maciej Zagozda (1998-2008)
  @Licence Microsoft Reciprocal License (Ms-RL)
  @Website http://www.codeplex.com/intelitechdelphirtns/
  @Version 2008/04/20 Added documentation support
}

unit ClipboardRoutines;

interface

uses
  Classes,
  Clipbrd,
  Controls,
  Dialogs,                
  ExtCtrls,
  Forms,
  Graphics,
  Messages,
  SysUtils,
  Windows;


function CopyStringListToClipboard( strlStringList: TStringList ): Boolean;
function PasteStringListFromClipboard( strlStringList: TStringList ): Boolean;
function RegisterClipBoardType( strnTypeName: AnsiString ): Word;

implementation

function CopyStringListToClipboard( strlStringList: TStringList ): Boolean;
var
  intgA: Integer;
  charA: array[0..10000] of Char;
  charB: array[0..1000] of Char
begin

  Result := True;

  try
    if strlStringList <> nil then
    begin
      StrCopy( charA,'' );

      for intgA := 0 to Pred( strlStringList.Count ) do
      begin

        StrPCopy( charB, strlStringList[intgA] + Chr( vk_return ) + Chr( 10 ));
        StrCat( charA, charB );

      end;//for

      ClipBoard.SetTextBuf( charA );
    end
    else
    begin

      Result := False;

    end;//if
  except

    Result := False;

  end;//try

end;

//_____________________________________________________________________________

function PasteStringListFromClipboard( strlStringList: TStringList ): Boolean;
var
  intgA, intgB, intgCount: Integer;
  strnString: AnsiString;
  charA: array[0..10000] of Char;
begin

  Result := True;

  if ( strlStringList <> nil ) and ( Clipboard.HasFormat( CF_TEXT )) then
  begin

    Clipboard.GetTextBuf( charA, 10000 );
    strnString := Clipboard.AsText;

    for intgB := 0 to Pred( StrLen( charA )) do
    begin
      if charA[intgB] = #13 then
      begin
        strlStringList.Add( '' );
        intgA := intgA + 1;
      end
      else
      begin
        if Ord( charA[intgB] ) > 20 then
        begin
          strlStringList[intgA] := strlStringList[intgA] + charA[intgB];
        end;//if
      end;//if
    end;//for

  end;//if

end;

//_____________________________________________________________________________

function RegisterClipBoardType( strnTypeName: AnsiString ): Word;
var
  charTypeName: PChar;
begin

 GetMem( charTypeName, Length( strnTypeName ) + 1 );
 StrPCopy( charTypeName, strnTypeName );
 Result := RegisterClipBoardFormat( charTypeName );
 FreeMem( charTypeName, Length( strnTypeName ) + 1 );

end;


end.
